﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.freegiftsale.ui {
    import flash.events.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import flash.text.*;
    import Display.aswingui.*;
    import flash.errors.*;

    public class TimerCellPanel extends JPanel {

        private static var CELL_SEPARATOR_FONT_SIZE:int = 24;
        private static var MILLIS_PER_HOUR:int = 3600000;
        private static var MILLIS_PER_MINUTE:int = 60000;
        private static var MILLIS_PER_SECOND:int = 1000;
        private static var RENDER_INTERVAL:int = 100;

        private var hoursPanel1:TimerCell;
        private var hoursPanel2:TimerCell;
        private var minutesPanel1:TimerCell;
        private var minutesPanel2:TimerCell;
        private var secondsPanel1:TimerCell;
        private var secondsPanel2:TimerCell;
        private var m_countdownDate:Date;

        public function TimerCellPanel(_arg1:Date){
            super(new FlowLayout(FlowLayout.LEFT, 1));
            this.m_countdownDate = _arg1;
            this.hoursPanel1 = new TimerCell();
            this.hoursPanel2 = new TimerCell();
            this.minutesPanel1 = new TimerCell();
            this.minutesPanel2 = new TimerCell();
            this.secondsPanel1 = new TimerCell();
            this.secondsPanel2 = new TimerCell();
            this.appendAll(this.hoursPanel1, this.hoursPanel2, this.createTimerCellSeparator(), this.minutesPanel1, this.minutesPanel2, this.createTimerCellSeparator(), this.secondsPanel1, this.secondsPanel2);
            this.renderTimerCells(null);
            var _local2:Timer = new Timer(RENDER_INTERVAL);
            _local2.addEventListener(TimerEvent.TIMER, this.renderTimerCells);
            _local2.start();
        }
        private function createTimerCellSeparator():JTextField{
            var _local1:TextFormat = new TextFormat();
            _local1.align = TextFormatAlign.LEFT;
            var _local2:JTextField = ASwingHelper.makeTextField(":", EmbeddedArt.TITLE_FONT, TimerCellPanel.CELL_SEPARATOR_FONT_SIZE, EmbeddedArt.lightishBlueTextColor, 3, _local1);
            ASwingHelper.setEasyBorder(_local2, -2, -2, 0);
            return (_local2);
        }
        private function renderTimerCells(_arg1:TimerEvent):void{
            var _local4:int;
            var _local5:Number;
            var _local6:int;
            var _local7:int;
            var _local2:Date = new Date();
            var _local3:Number = (this.m_countdownDate.getTime() - _local2.getTime());
            if (_local3 < 0){
                this.setDisplay(0, 0, 0);
            } else {
                if (_local3 >= ((99 * MILLIS_PER_HOUR) + (99 * MILLIS_PER_MINUTE))){
                    throw (new IllegalOperationError("Max of 99 hours ahead FREE_GIFT_OFFER_END_DATE RuntimeVar is over 99 hours ahead!"));
                };
                _local4 = (_local3 / TimerCellPanel.MILLIS_PER_HOUR);
                _local5 = (_local3 - (_local4 * TimerCellPanel.MILLIS_PER_HOUR));
                _local6 = (_local5 / TimerCellPanel.MILLIS_PER_MINUTE);
                _local5 = (_local5 - (_local6 * TimerCellPanel.MILLIS_PER_MINUTE));
                _local7 = (_local5 / TimerCellPanel.MILLIS_PER_SECOND);
                this.setDisplay(_local4, _local6, _local7);
            };
        }
        private function setDisplay(_arg1:int, _arg2:int, _arg3:int):void{
            this.setDigitStrings(_arg1, this.hoursPanel1, this.hoursPanel2);
            this.setDigitStrings(_arg2, this.minutesPanel1, this.minutesPanel2);
            this.setDigitStrings(_arg3, this.secondsPanel1, this.secondsPanel2);
        }
        private function setDigitStrings(_arg1:int, _arg2:TimerCell, _arg3:TimerCell):void{
            var _local4:String;
            if (_arg1 > 99){
                return;
            };
            if (_arg1 < 0){
                return;
            };
            if ((((_arg1 >= 0)) && ((_arg1 < 10)))){
                _arg2.digit = 0;
                _arg3.digit = _arg1;
            } else {
                _local4 = String(_arg1);
                _arg2.digit = parseInt(_local4.charAt(0));
                _arg3.digit = parseInt(_local4.charAt(1));
            };
        }

    }
}//package Modules.freegiftsale.ui 
